﻿using System;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace zTalk
{
    [ValueConversion(typeof(UserStatus), typeof(ImageSource))]
    class StatusConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, 
            System.Globalization.CultureInfo culture)
        {
            UserStatus status = (UserStatus)value;

            string uri = "offline";

            if (status == UserStatus.ONLINE)
            {
                uri = "online";
            }
            else if (status == UserStatus.AFK)
            {
                uri = "afk";
            }

            return new BitmapImage(new Uri(string.Format(
                "pack://application:,,,/zTalk;component/resources/{0}.png", uri
            )));
        }

        public object ConvertBack(object value, Type targetType, object parameter, 
            System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}
